﻿@typeparam TItem

@if (items is null)
{
    @Loading
}
else if (!items.Any())
{
    @Empty
}
else
{
    <div class="list-group @ListGroupClass">
        @foreach (var item in items)
        {
            <div class="list-group-item">
                @if (Item is not null)
                {
                    @Item(item)
                }
            </div>
        }
    </div>
}

@code {
    IEnumerable<TItem>? items;

    [Parameter, EditorRequired] public Func<Task<IEnumerable<TItem>>>? Loader { get; set; }
    [Parameter] public RenderFragment? Loading { get; set; }
    [Parameter] public RenderFragment? Empty { get; set; }
    [Parameter, EditorRequired] public RenderFragment<TItem>? Item { get; set; }
    [Parameter] public string? ListGroupClass { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        if (Loader is not null)
        {
            items = await Loader();
        }
    }
}
